package com.sky.controller.admin;

import com.aliyun.utils.AliOSSUtils;
import com.sky.constant.MessageConstant;
import com.sky.exception.BaseException;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Api(tags = "通用接口")
@RestController
public class CommonController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    @ApiOperation("文件上传")
    @PostMapping("/admin/common/upload")
    public Result upload(MultipartFile file)  {
        try {
            String url = aliOSSUtils.upload(file);
            return Result.success(url);
        } catch (IOException e) {
            throw new BaseException(MessageConstant.UPLOAD_FAILED);
        }
    }
}
